﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BIZ;
using System.Web.Script.Serialization;
using System.Collections;
using DomainModel;
namespace joyAdmin.Controllers
{
    [DomainConfirmationFilter]
    [BIZ.AdminFilter]
    public class IndexController : Controller
    {
        //
        // GET: /Index/
        BIZ.InfomationPublishOper ips = new InfomationPublishOper();
        public ActionResult Notice()
        {
            cmsOper.CheckUserRights("Notice");
            return View();
        }
        public ActionResult aboutreader()
        {
            cmsOper.CheckUserRights("aboutreader");
            return View();
        }
        public ActionResult handbook()
        {
            cmsOper.CheckUserRights("handbook");
            return View();
        }
        public ActionResult readshare()
        {
            cmsOper.CheckUserRights("readshare");
            return View();
        }
        public ActionResult choosebook()
        {
            cmsOper.CheckUserRights("choosebook");
            return View();
        }
        public ActionResult ourstar()
        {
            cmsOper.CheckUserRights("ourstar");
            return View();
        }
        public ActionResult bookrecommend()
        {
            cmsOper.CheckUserRights("bookrecommend");
            return View();
        }
        public ActionResult seriesbook()
        {
            cmsOper.CheckUserRights("seriesbook");
            return View();
        }
        public ActionResult lunbo()
        {
            cmsOper.CheckUserRights("lunbo");
            return View();
        }
        public ActionResult hotbook()
        {
            cmsOper.CheckUserRights("hotbook");
            return View();
        }
        public JsonResult getlist()
        {
            int pageno = Convert.ToInt32(Request.Params["pageno"]);
            int pagesize = Convert.ToInt32(Request.Params["pagesize"]);
            int template = Convert.ToInt32(Request.Params["template"]);
            return Json(ips.getlist(pageno, pagesize, template));
        }
        [ValidateInput(false)]
        public ActionResult saveInfomationPublish()
        {
            InfomationPublish _staff = new JavaScriptSerializer().Deserialize<InfomationPublish>(Request.Form["infomationpublish"].ToString());

            if (_staff.i_id != 0)
            {
                _staff.i_updateTime = DateTime.Now;
                _staff.i_lastUser = ((DomainModel.cmsuser)Session["cmsuser"]).id;
                _staff.i_addTime = _staff.i_addTime.ToLocalTime();
                _staff.i_startTime = _staff.i_startTime.ToLocalTime();
                _staff.i_endTime = _staff.i_endTime.ToLocalTime();
            }
            else
            {
                _staff.i_addTime = DateTime.Now;
                _staff.i_user = ((DomainModel.cmsuser)Session["cmsuser"]).id;
            }
            ips.save(_staff);
            return Json(_staff);
        }
        public JsonResult getinfomationbyid()
        {
            int id = Convert.ToInt32(Request.Params["res"]);
            IList list = ips.getinfomationbyid(id);
            if (list.Count > 0)
                return Json(list[0]);
            else
                return Json("");
        }

        public JsonResult deleteinfomation()
        {
            int id = int.Parse(Request.Form["res"]);

            return Json(ips.delete(id));
        }
    }
}
